import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-10-02
 * Time: 10:41
 */
//简单模拟实现 线程池
class MyPollThread {
    static BlockingDeque<Runnable> queue = new LinkedBlockingDeque<>();

    public void submit (Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
    public static MyPollThread newMyPollThread(int n) {
        for (int i = 0; i < n; i++) {
            Thread t = new Thread(()-> {
                while (true) {
                    try {
                        Runnable runnable = queue.take();
                        runnable.run();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            t.start();
        }
        return new MyPollThread();
    }
}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        MyPollThread myPollThread = MyPollThread.newMyPollThread(4);

        for (int i = 0; i < 1000; i++) {
            myPollThread.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName() + " hello");
                }
            });
        }
    }
}
